//
//  AmapComponent.swift
//  demo3
// 高德地图测试
//  Created by hanweiguang on 2018/12/29.
//  Copyright © 2018年 hanweiguang. All rights reserved.
//


import Foundation
import WeexSDK

 
  extension AmapComponent: MAMapViewDelegate {
    
 //     var moveCamera: NSDictionary?
    @objc    override   open func loadView() -> UIView {
        self.mapView = MAMapView()
        self.mapView.showsUserLocation=true
        self.mapView.delegate = self
        self.mapView.showsCompass = false
        self.mapView.showsScale = true
        AMapServices.shared().enableHTTPS = true
        self.mapView.setZoomLevel(14, animated: true)
        return self.mapView
    }
  
    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//             print("地图没有viewDidLoad化")
//    }
//
//
//    override init(ref: String, type: String, styles: [AnyHashable : Any]?, attributes: [AnyHashable : Any]? = nil, events: [Any]?, weexInstance: WXSDKInstance) {
//        super.init(ref: ref, type: type, styles: styles, attributes: attributes, events: events, weexInstance: weexInstance);
//
//        if let moveCamera = attributes?["moveCamera"] as? NSDictionary {
//            self.moveCamera = moveCamera
//        }
//
//       print("地图没有init化\(self.moveCamera)")
//    }
//
    @objc func addMarker(_ aa: String) {

        print("weex 调用 扩展方法  \(aa)")

    }
   @objc    open func mapViewDidFinishLoadingMap(_ mapView: MAMapView){
        print("加载完成地图+++++++++++")

    }
    
    
    override open func updateAttributes(_ attributes: [AnyHashable : Any] = [:]) {
        super.updateAttributes(attributes)
        if let moveCamera = attributes["moveCamera"] as? NSDictionary {
            self.moveCamera = moveCamera as! [AnyHashable : Any]

        }
        if mapView != nil {

            print("地图没有mapView化\(self.moveCamera)")
            mapView.setCenter(CLLocationCoordinate2D(latitude:self.moveCamera?["latitude"] as! CLLocationDegrees, longitude: self.moveCamera?["longitude"] as! CLLocationDegrees), animated: true)
            print( "可以操作地图" )
            let pointAnnotation = MAPointAnnotation()
            pointAnnotation.coordinate = CLLocationCoordinate2D(latitude:self.moveCamera?["latitude"] as! CLLocationDegrees, longitude: self.moveCamera?["longitude"] as! CLLocationDegrees)
            pointAnnotation.title = "方恒国际"
            pointAnnotation.subtitle = "阜通东大街6号"
            mapView.addAnnotation(pointAnnotation)
        }


    }
    
}

